import { createRouter, createWebHistory, RouteRecordRaw } from "vue-router";
import { etfRoutes } from "./etf-routers";

const routes: RouteRecordRaw[] = [
  ...etfRoutes,
  {
    name: "404",
    path: "/404",
    component: () => import("@/views/not-found/not-found.vue"),
    meta: {
      pageName: "活动中心",
    },
  },
  {
    path: "/:catchAll(.*)", // 此处需特别注意至于最底部
    redirect: "/404",
  },
];
// 路由器
const router = createRouter({
  // 使用 history 路由模式需要在 nginx location 中添加:
  // try_files $uri $uri/ /${VITE_MODULE_NAME}/index.html; 防止刷新时出现 nginx 404 报错页面
  history: createWebHistory(import.meta.env.BASE_URL), // HTML5模式
  routes,
});

router.beforeEach((to, from, next) => {
  document.title = to.meta.pageName as string;
  next();
});

export default router;
